#cmake file for test
#author:guyadong
#created:2018/05/10
cmake_minimum_required( VERSION 3.0 )
cmake_policy(SET CMP0048 NEW)
# 3.0以上版本才允许使用VERSION option
project(faceapi_test VERSION 1.0.0 LANGUAGES C CXX)
#判断编译类型和版本是否满足编译要求
if(MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19)
	message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") 
	message(STATUS "CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}" )
elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5)
	message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") 
	message(STATUS "CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}" )
else()
	message(FATAL_ERROR "compiler required: Visual Studio 2015 OR gcc 5.2.0 above" )
endif()
# includes utils.cmake module
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake/Modules" "${PROJECT_SOURCE_DIR}/../dependencies/cmake/Modules")
include (utils)
cxx11_support()
if(MSVC)
	#关闭C4819警告
	add_definitions("/wd4819")		
	message(STATUS "optional:/wd4819")
	#关闭CRT_SECURE警告
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	message(STATUS "optional:-D_CRT_SECURE_NO_WARNINGS")
endif(MSVC)
if(CMAKE_COMPILER_IS_GNUCXX)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++" )
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++" )
	if(WIN32)
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc" )
		set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc" )
	endif()
endif()
##############设置目标文件生成位置#####################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set( COMMON_SOURCE_CPP_DIR "${CMAKE_SOURCE_DIR}/../dependencies/common_source_cpp")
if( IS_DIRECTORY "${COMMON_SOURCE_CPP_DIR}" )
    # common_source_cpp.out参数用于指定外部文件夹在输出文件夹中的位置
    add_subdirectory( ${COMMON_SOURCE_CPP_DIR} common_source_cpp.out)
else()
    message(FATAL_ERROR   "INVALID FOLDER 'COMMON_SOURCE_CPP_DIR'=${COMMON_SOURCE_CPP_DIR}" )
endif()

find_package(faceapiclient REQUIRED )
find_package(gfaux_tools REQUIRED )

# 定义 /MT,MD 后缀
set(_static_postfix "")
if(MSVC)
	if(Boost_USE_STATIC_RUNTIME)
		set(_static_postfix _mt)
	else()
		set(_static_postfix _md)
	endif(Boost_USE_STATIC_RUNTIME)
endif(MSVC)

set(_linke_libs gdface::faceapiclient${_static_postfix} common_source)
set(_test_targets)
add_executable(connect_test connect_test.cpp )
target_link_libraries(connect_test ${_linke_libs})
add_executable(multi_thread_test multi_thread_test.cpp ${DEPENDENT_SOURCE_DIR}/ThreadPool.cpp)

list(APPEND _test_targets connect_test)

add_executable(detect_face_test detect_face_test.cpp)
add_executable(compare_face_test compare_face_test.cpp)

set(_targets_with_ui detect_face_test compare_face_test multi_thread_test)
list(APPEND _test_targets ${_targets_with_ui})
foreach(_target ${_targets_with_ui})
	target_link_libraries(${_target} ${_linke_libs} gdface::gfaux_tools${_static_postfix})
endforeach(_target)

if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) 
	# 复制测试图像到${PROJECT_BINARY_DIR}
	file(RELATIVE_PATH _current_folder ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
	file(COPY ${CMAKE_CURRENT_LIST_DIR}/images DESTINATION ${PROJECT_BINARY_DIR}/${_current_folder})
	message(STATUS "copy ${CMAKE_CURRENT_LIST_DIR}/images to ${PROJECT_BINARY_DIR}/${_current_folder}")
	unset(_current_folder)
endif()
set_target_properties(${_test_targets} PROPERTIES FOLDER "test")
set_property(TARGET ${_test_targets} APPEND PROPERTY COMPILE_OPTIONS $<$<CXX_COMPILER_ID:MSVC>:/wd4275 /wd4251>)
################安装脚本#################
# 安装exe
#install(TARGETS ${_test_targets} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} )
# 安装测试图像文件
#install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/images DESTINATION ${RUNTIME_INSTALL_DIR})
